<?php
namespace app\common\controller;

use think\Controller;
use think\Request;
use app\common\model\Business\Business;
use app\common\library\util\Token;

class Hotel extends Controller{
    protected $noLogin = [];
    protected $request = null;
    protected $business = null;
    public function __construct(Request $request)
    {
        parent::__construct();
        $this->request = $request;
        if(in_array('*',$this->noLogin)==in_array($this->request->action(),$this->noLogin)){
            $result = $this->isLogin();
            if($result['code']==0){
                $this->result(null,404,$result['msg']);
            }
        }
    }
    protected function isLogin($token=null)
    {
        // $this->success($this->request->header('Authorization'));
        $token = $token==null?$this->request->header('Authorization'):$token;
        if(!$token){
            return [
                'code'=>0,
                'msg'=>'token不存在',
            ];
        }
        // halt($token);
        $status = Token::checkToken($token);
        // halt($status);
        if($status["code"]==1){
            $this->business = Business::where("id",$status["data"]["id"])->find();
            if($this->business['mobile']==$status["data"]["mobile"]){
                return [
                    'code'=>1,
                    'msg'=>'token正确',
                    'data'=>$this->business,
                ];
            }
        }
        return [
            'code'=>0,
            'msg'=>$status['msg'],
        ];
    }
}